package cn.com.shaom.learning.sb.web.websocket.topic;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * ClassName: WebSocketController
 * Description:
 * Date: 2017/12/26 9:53 【需求编号】
 *
 * @author Shaom
 * @version V1.0.0
 */
@Controller
public class WebSocketController {

    // 类似与 RequestMapping
    @MessageMapping("/welcome")
    // 当服务端有消息时，会对订阅了 @SendTo 中的路径的浏览器发送消息
    @SendTo("/topic/getResponse")
    public WsResponse welcome(WsRequest wsRequest) throws Exception {
        Thread.sleep(3000L);
        return new WsResponse("Welcome WebSocket Topic , " + wsRequest.getName());
    }
}
